package com.example.booklist.config;

import com.example.booklist.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: ErrorHandler
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2023/11/29 21:13
 * @Version 1.0
 */
@ResponseBody
@Slf4j
@ControllerAdvice
public class ErrorHandler {
    @ExceptionHandler
    public Result exception(Exception e) {
        log.error("发生异常, e:{}", e.getMessage());
        return Result.fail("内部错误");
    }
    @ExceptionHandler
    public Result exception(NullPointerException e) {
        log.error("发生异常, e:{}", e.getMessage());
        return Result.fail("内部错误");
    }

}
